/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SensorView;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.sensor.*;
import sUtils.*;



/**
 * @author thomas.s
 */
public class SensorView extends MIDlet implements CommandListener {

    private Command exitCommand;
    private Command thermCommand;
    private Command thermSet;
    private Display display;
    private SensorCanvas canvas;
    private TextBox therm2;
    private Form f;

    
    public SensorView () {
        Lang.init();
        exitCommand = new Command ( Lang.word("Quit","Beenden"), Command.EXIT, 0);
        thermCommand = new Command ( Lang.word("Therm.","Temperatur"), Command.ITEM, 2);
        thermSet = new Command ( Lang.word("Set","Setze"), Command.ITEM, 3);

        display = Display.getDisplay (this);
        canvas = new SensorCanvas ();
        SensorInfo[] sensors = SensorManager.findSensors(null,null);
        for ( int i=0; i<sensors.length; i++ )
            canvas.setSensor(sensors[i].getQuantity(),sensors[i].getUrl());
        canvas.addCommand (exitCommand);
        canvas.addCommand (thermCommand);
        canvas.setCommandListener (this);
    }

    public void startApp () {
        display.setCurrent (canvas);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction (Command c, Displayable s) {
        if (c == exitCommand) {
            destroyApp (true);
            notifyDestroyed ();
        }
        if (c == thermSet)
        {
            canvas.setTherm(therm2.getString());
            display.setCurrent(canvas);
        }
        if (c == thermCommand)
        {
            therm2 = new TextBox( Lang.word("Therm value","Temp Wert (Therm)"), "", 32, TextField.DECIMAL);
            therm2.addCommand(thermSet);
            therm2.setCommandListener(this);
            display.setCurrent(therm2);
        }

    }
}


